package com.stockz.train.manager;

import java.util.Date;
import java.util.Map;

import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;

import com.stockz.core.util.Global;
import com.stockz.core.util.SpringUtil;
import com.stockz.train.domain.intf.TrainingMarker;
import com.stockz.train.domain.model.TrainingSession;
import com.stockz.train.util.TrainingConstant;

@Component
public class TrainingManager {

	
	public void start(Date startDate, double startAmount){
		Global.put(TrainingConstant.isTrainingMode, Boolean.TRUE);
		TrainingSession trainingSession = new TrainingSession(startDate, startAmount);
		((ClassPathXmlApplicationContext)SpringUtil.getApplicationContext()).refresh();
		Map<String, TrainingMarker> map = SpringUtil.getApplicationContext().getBeansOfType(TrainingMarker.class);
		for(TrainingMarker marker : map.values()){
			marker.setTrainingSession(trainingSession);
		}
	}
	
	
	public void stop(){
		Global.put(TrainingConstant.isTrainingMode, Boolean.FALSE);
		((ClassPathXmlApplicationContext)SpringUtil.getApplicationContext()).refresh();
	}
	
}
